package com.ym.manager.admin.bank;

import com.ym.manager.sys.model.AdminUser;
import com.ym.utils.Pages;
import com.ym.utils.ResultUtil;
import com.ym.web.bind.CurrentUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * @Author: dhf
 * @ClassName: BankController
 * @Date: 2022/9/2 22:34
 * @Description:
 * @Version: 1.0
 */
@Controller
@RequestMapping("/bank")
public class BankController {
    @Autowired
    private BankServer bankServer;

    @RequestMapping("/index")
    public String index(){
        return "/bank/list";
    }

    @ResponseBody
    @RequestMapping("/list")
    public String list(@RequestParam(defaultValue = "1") int page,
                       @RequestParam(defaultValue = "20")int limit,
                       @CurrentUser AdminUser user){
        Map<String,Object> result = ResultUtil.result();
        try {
            Pages<Map<String,Object>> pages = bankServer.getList(page,limit);
            //查询数据
            result.put("data",pages.getList());
            result.put("recordsTotal",pages.getTotal());
            result.put("recordsFiltered",pages.getTotal());
        }catch (Exception e){
            e.printStackTrace();
            result.put("code",-1000);
            result.put("msg","系统异常");
        }
        return ResultUtil.toJSON(result);
    }
}
